package main

import (
	"context"
	"log"

	"grpc-go-demo/echo"

	"google.golang.org/grpc"
)

func main() {
	connect, err := grpc.Dial("localhost:8080", grpc.WithInsecure())
	if err != nil {
		log.Fatal(err.Error())
	}
	defer connect.Close()

	client := echo.NewEchoClient(connect)

	stream, err := client.ClientStreamEcho(context.Background())
	if err != nil {
		log.Fatalln(err.Error())
	}
	for i := int64(0); i < 2; i++ {
		err := stream.Send(&echo.EchoRequest{Message: "hello word"})
		if err != nil {
			log.Println(err.Error())
			continue
		}
	}
	resp, err := stream.CloseAndRecv()
	if err != nil {
		log.Fatalln(err.Error())
	}
	log.Println("sum:", resp.GetMessage())
}
